/**   
* @Title: CustomerServiceImpl.java 
* @Package com.kerrykidz.filemanagement.service.impl 
* @Description: 
* Copyright: Copyright (c) 2014 
* Company:wuwh team by iss
* @author: ScreenJxp   
* @date: 2014年9月5日 下午6:06:17 
* @version: V1.0
*
*/
package com.kerrykidz.filemanagement.service.impl;

import java.util.List;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kerrykidz.filemanagement.dao.mapper.CarCareFormEntityMapper;
import com.kerrykidz.filemanagement.dao.model.CarCareFormEntity;
import com.kerrykidz.filemanagement.service.ICustomerService;
import com.kerrykidz.system.util.UserUtil;
import com.kerrykidz.system.vo.UserInfo;
import com.kerrykidz.workflow.service.IWorkflowService;
import com.kerrykidz.workflow.vo.WorkflowVo;
import com.rdp.framework.exception.RDPException;
@Service
public class CustomerServiceImpl implements ICustomerService {
	@Autowired
	private CarCareFormEntityMapper carCareFormEntityMapper;
	
	@Autowired 
	private IWorkflowService workflowService;
	public List<CarCareFormEntity> findServiceList(CarCareFormEntity entity)
			throws RDPException {
			List<CarCareFormEntity> carList= carCareFormEntityMapper.findServiceList(entity);
			  WorkflowVo vo=new WorkflowVo();
			  String  userId= UserUtil.getUserFromSession().getUserId();
			//关联流程处理人
			for(CarCareFormEntity view:carList){
				if("1".equals(view.getCareType())){//投诉
					vo.setIsStartUser(userId.equals(view.getApplyBy())?"1":"0");
					view.setWorkflowVo(vo);
				}else{
					if("1".equals(view.getStatus())){
					  vo.setIsStartUser(userId.equals(view.getApplyBy())?"1":"0");
					  view.setWorkflowVo(vo);
					}else{
						view.setWorkflowVo(workflowService.getWorkflowVo(view.getFkFlowinstId(), view.getStatus(),UserUtil.getUserFromSession()));
					}
				}
			}
			return carList;
			
	}
	public void saveCustomerService(CarCareFormEntity entity)
			throws RDPException {
		  carCareFormEntityMapper.saveCustomerService(entity);
	}
	public void updateCustomerService(CarCareFormEntity entity)
			throws RDPException {
		  carCareFormEntityMapper.updateCustomerService(entity);
		  
	}
	public void deleteCustomerService(String pkCareformId) throws RDPException {
		  carCareFormEntityMapper.deleteCustomerService(pkCareformId);
	}
	public CarCareFormEntity findServiceById(String pkCareformId,String userId)
			throws RDPException {
			CarCareFormEntity car= carCareFormEntityMapper.findServiceById(pkCareformId);
			UserInfo user = UserUtil.getUserFromSession();
			if(!"".equals(userId)&&car!=null){
				WorkflowVo work=workflowService.getWorkflowVo(car.getFkFlowinstId(), car.getStatus(), UserUtil.getUserFromSession());
				work.setOptHisVoList(workflowService.findOpinions(car.getFkFlowinstId(),user));
				car.setWorkflowVo(work);
			}
			return car;
	}
	public CarCareFormEntity findForApply(String pkCareformId)
			throws RDPException {
			return  carCareFormEntityMapper.findForApply(pkCareformId);
	}
  
}
